package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class FreeController {
    @GetMapping("/basic")
    public String test(Model model) {
        //1.纯文本形式的参数
        model.addAttribute("name", "freemarker");
        //2.实体类相关的参数

        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        model.addAttribute("stu", student);

        return "01-basic";
    }

    @GetMapping("/basic1")
    public ModelAndView test1() {
        ModelAndView andView = new ModelAndView();
        //1.纯文本形式的参数
        andView.addObject("name", "freemarker");
        //2.实体类相关的参数

        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        andView.addObject("stu", student);
        andView.setViewName("01-basic");
        return andView;
    }

    @GetMapping("/basic2")
    public String test1(ModelMap modelMap) {
        //1.纯文本形式的参数
        modelMap.put("name", "freemarker");
        //2.实体类相关的参数

        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        modelMap.put("stu", student);

        return "01-basic";
    }

    @GetMapping("/list")
    public String list(Model model) {
        //1.纯文本形式的参数
        model.addAttribute("name", "freemarker");
        //2.实体类相关的参数

        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        student.setMoney(100.00f);

        Student student2 = new Student();
        student2.setName("郭建成");
        student2.setAge(12);
        student2.setMoney(200.0f);

        List<Student> arrayList = new ArrayList<>();
        arrayList.add(student);
        arrayList.add(student2);

        model.addAttribute("date1", new Date());
        model.addAttribute("date2", new Date());
        model.addAttribute("bank", "工商银行");

        model.addAttribute("stus", arrayList);
        return "02-list";
    }

}
